<?php

if ($_FILES["test_file"]["error"] > 0)
{
	echo "Error: " . $_FILES["test_file"]["error"] . "<br />";
}
else
{
	$filetype=strrchr($_FILES["test_file"]["name"],".");
	$filetype=substr($filetype,1,strlen($filetype));
	if(in_array($filetype, array("png","jpg","gif"))){
		$upfileName = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',30)),0,30).'.'.$filetype;
		$filename='../image/uptemp/'.$upfileName;
		move_uploaded_file($_FILES["test_file"]["tmp_name"],$filename);
		list($width, $height) = getimagesize($filename);
		
		$flag = $_POST['submits'];
		$cset = $_POST['cset'];
		if($flag == 1){
			$height = $height * (356/$width);
			$width = 356;
			echo '<script type="text/javascript">parent.TouClick.cropzoomLoadImage("source/plugin/touclick/image/uptemp/'.$upfileName.'",'.$width.','.$height.');
				parent.document.getElementById("preupimg").style.display = "block";</script>';
		}else{
			if($width > 60 || $height > 60){
				echo "<script type='text/javascript' charset={$cset} >alert('你上传的图片高或宽大于60px!');</script>";
			}else{
				echo '<script type="text/javascript" '."charset={$cset} ".'>parent.document.getElementById("smallpic").value = "source/plugin/touclick/image/uptemp/'.$upfileName.'";alert("上传成功!");</script>';
			}
		}
	}else
	{
		echo '<script type="text/javascript">alert("&#22270;&#29255;&#26684;&#24335;&#38750; png,jpg &#25110; gif!");</script>';
	}
}
?>